/*
* jiyan1
*/
package com.jiyan.scene.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.jiyan.core.entity.BeanRet;
import com.jiyan.core.entity.Page;
import com.jiyan.core.tools.redis.RedisUtils;
import com.jiyan.scene.entity.Scene;
import com.jiyan.scene.service.SceneSV;

/**
* 场景 控制器
*
* @author jiyan
*/
@RestController
@RequestMapping("/scene")
@Slf4j
@Api(value = "场景控制器", description = "场景控制器")
public class SceneCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private SceneSV sceneSV;

    /**
    * 查询Scene一个详情信息
    * @param id 
    * @param code 编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询Scene一个详情信息", notes = "查询Scene一个详情信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "编码",dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public Scene load(java.lang.Long id,java.lang.String code) {
        if(id==null){
        return null;
        }
        if(code==null){
        return null;
        }
        Scene scene = sceneSV.load(id,code);
        log.info(JSON.toJSONString(scene));
        return scene;
    }


    /**
    * 根据条件id查询Scene一个详情信息
    *
    * @param id 
    * @return BeanRet
    */
    @ApiOperation(value = "查询Scene一个详情信息", notes = "查询Scene一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public Scene loadById(@PathVariable java.lang.Long id) {
        if(id==null){
           return null;
        }
        Scene scene = sceneSV.loadById(id);
        log.info(JSON.toJSONString(scene));
        return scene;
    }
    /**
    * 根据条件code查询Scene一个详情信息
    *
    * @param code 编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询Scene一个详情信息", notes = "查询Scene一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "code", value = "编码",dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public Scene loadByCode(@PathVariable java.lang.String code) {
        if(code==null){
           return null;
        }
        Scene scene = sceneSV.loadByCode(code);
        log.info(JSON.toJSONString(scene));
        return scene;
    }


    /**
    * 查询Scene信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询Scene信息集合", notes = "查询Scene信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<Scene> list(@RequestBody @ApiIgnore Scene scene,Integer curPage,Integer pageSize) {
        Page<Scene> page=new Page<Scene>(pageSize,curPage);
        List<Scene> scenes = sceneSV.list(scene,page.genRowStart(),page.getPageSize());
        int total = sceneSV.count(scene);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return scenes;
    }


    /**
    * 查询Scene信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询Scene信息集合", notes = "查询Scene信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<Scene> listByPk(java.lang.Long id,java.lang.String code,Integer curPage,Integer pageSize) {
        Page<Scene> page=new Page<Scene>(pageSize,curPage);
        List<Scene> scenes = sceneSV.list(id,code, page.genRowStart(),page.getPageSize());
        int total = sceneSV.count(id,code);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return scenes;
    }

    /**
    * 统计Scene信息数量根据主键
    *
    * @return 总条数
    */
    @ApiOperation(value = " 统计Scene信息数量根据主键", notes = " 统计Scene信息数量根据主键")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id,java.lang.String code) {
        return sceneSV.count(id,code);
    }

    /**
    * 统计Scene信息数量
    *
    * @return 总条数
    */
    @ApiOperation(value = "统计Scene信息数量", notes = "统计Scene信息数量")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
    @ApiImplicitParam(name = "name", value = "场景名称", paramType = "query"),
    @ApiImplicitParam(name = "summary", value = "场景说明", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody Scene scene) {
        return sceneSV.count(scene);
    }



    /**
    * 创建Scene
    *
    * @return BeanRet
    */
    @ApiOperation(value = "创建Scene", notes = "创建Scene")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "name", value = "场景名称", paramType = "query"),
        @ApiImplicitParam(name = "summary", value = "场景说明", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public Scene build(@RequestBody @ApiIgnore Scene scene) {
        sceneSV.save(scene);
        return scene;
    }


    /**
    * 修改Scene
    *
    * @return BeanRet
    */
    @ApiOperation(value = "修改Scene", notes = "修改Scene")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
        @ApiImplicitParam(name = "name", value = "场景名称", paramType = "query"),
        @ApiImplicitParam(name = "summary", value = "场景说明", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public Scene modify(@RequestBody @ApiIgnore Scene scene) {
        sceneSV.modify(scene);
        return scene;
    }

    /**
    * 删除Scene
    *
    * @return BeanRet
    */
    @ApiOperation(value = "删除Scene", notes = "删除Scene")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id,java.lang.String code) {
        sceneSV.delete(id,code);
        return BeanRet.create(true, "删除Scene成功");
    }

}
